<template>
  <div>
    <el-upload
      :action="uploadUrl"
      :before-upload="handleBeforeUpload"
      :on-success="handleUploadSuccess"
      :on-error="handleUploadError"
      name="file"
      :show-file-list="false"
      :headers="headers"
      style="display: none"
      ref="upload"
      v-if="this.type == 'url'"
    >
    </el-upload>
    <div class="editor-wrapper">
      <div class="editor" ref="editor" :style="styles"></div>
    </div>
    
    <!-- HTML源代码查看/编辑对话框 -->
    <el-dialog
      title="HTML源代码"
      :visible.sync="sourceCodeDialogVisible"
      width="85%"
      :close-on-click-modal="false"
      :modal="false"
      append-to-body
      class="source-code-dialog"
      top="8vh"
    >
      <div class="source-code-container">
        <div class="source-code-header">
          <span class="source-code-tip">在此编辑 HTML 源代码，修改后将应用到编辑器</span>
        </div>
        <el-input
          type="textarea"
          ref="sourceCodeTextarea"
          v-model="sourceCodeContent"
          :rows="20"
          placeholder="请输入HTML源代码..."
          class="source-code-textarea"
          :autosize="{ minRows: 20, maxRows: 30 }"
        />
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelSourceCode" class="cancel-btn">取 消</el-button>
        <el-button type="primary" @click="applySourceCode" class="apply-btn">应 用</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import Quill from "quill";
import "quill/dist/quill.core.css";
import "quill/dist/quill.snow.css";
import "quill/dist/quill.bubble.css";
import { getToken } from "@/utils/auth";

export default {
  name: "Editor",
  props: {
    /* 编辑器的内容 */
    value: {
      type: String,
      default: "",
    },
    /* 高度 */
    height: {
      type: Number,
      default: null,
    },
    /* 最小高度 */
    minHeight: {
      type: Number,
      default: null,
    },
    /* 只读 */
    readOnly: {
      type: Boolean,
      default: false,
    },
    /* 上传文件大小限制(MB) */
    fileSize: {
      type: Number,
      default: 5,
    },
    /* 类型（base64格式、url格式） */
    type: {
      type: String,
      default: "url",
    }
  },
  data() {
    return {
      uploadUrl: process.env.VUE_APP_BASE_API + "/common/upload", // 上传的图片服务器地址
      headers: {
        Authorization: "Bearer " + getToken()
      },
      Quill: null,
      currentValue: "",
      sourceCodeDialogVisible: false, // 源代码对话框显示状态
      sourceCodeContent: "", // 源代码内容
      editorEnabled: true, // 编辑器是否启用（用于临时禁用）
      options: {
        theme: "snow",
        bounds: document.body,
        debug: "warn",
        modules: {
          // 工具栏配置
          toolbar: [
            ["bold", "italic", "underline", "strike"],       // 加粗 斜体 下划线 删除线
            ["blockquote", "code-block"],                    // 引用  代码块
            [{ list: "ordered" }, { list: "bullet" }],       // 有序、无序列表
            [{ indent: "-1" }, { indent: "+1" }],            // 缩进
            [{ size: ["small", false, "large", "huge"] }],   // 字体大小
            [{ header: [1, 2, 3, 4, 5, 6, false] }],         // 标题
            [{ color: [] }, { background: [] }],             // 字体颜色、字体背景颜色
            [{ align: [] }],                                 // 对齐方式
            ["clean"],                                       // 清除文本格式
            ["link", "image", "video"]                       // 链接、图片、视频
          ],
        },
        placeholder: "请输入内容",
        readOnly: this.readOnly,
      },
    };
  },
  computed: {
    styles() {
      let style = {};
      if (this.minHeight) {
        style.minHeight = `${this.minHeight}px`;
      }
      if (this.height) {
        style.height = `${this.height}px`;
      }
      return style;
    },
  },
  watch: {
    value: {
      handler(val) {
        if (val !== this.currentValue) {
          this.currentValue = val === null ? "" : val;
          if (this.Quill) {
            this.Quill.pasteHTML(this.currentValue);
          }
        }
      },
      immediate: true,
    },
    // 监听对话框打开状态，移除遮罩层并处理焦点
    sourceCodeDialogVisible(newVal) {
      if (newVal) {
        // 让编辑器失焦，防止键盘事件被编辑器捕获
        if (this.Quill) {
          // 临时禁用编辑器，防止键盘事件被捕获
          this.Quill.enable(false);
          this.Quill.blur();
          
          // 同时移除编辑器的焦点状态
          const editorElement = this.$refs.editor;
          if (editorElement) {
            const editorContainer = editorElement.querySelector('.ql-editor');
            if (editorContainer) {
              editorContainer.blur();
              // 设置不可编辑样式，防止意外编辑
              editorContainer.setAttribute('contenteditable', 'false');
            }
          }
        }
        
        // 对话框打开时，延迟移除遮罩层（确保遮罩层已创建）
        this.$nextTick(() => {
          this.removeModalOverlay();
          
          // 将焦点移到文本域
          if (this.$refs.sourceCodeTextarea && this.$refs.sourceCodeTextarea.$el) {
            const textarea = this.$refs.sourceCodeTextarea.$el.querySelector('textarea');
            if (textarea) {
              setTimeout(() => {
                textarea.focus();
              }, 150);
            }
          }
        });
        
        // 多次尝试移除，确保成功
        setTimeout(() => {
          this.removeModalOverlay();
        }, 50);
        setTimeout(() => {
          this.removeModalOverlay();
        }, 100);
      } else {
        // 对话框关闭时，重新启用编辑器
        if (this.Quill) {
          this.Quill.enable(true);
          
          // 恢复编辑器可编辑状态
          const editorElement = this.$refs.editor;
          if (editorElement) {
            const editorContainer = editorElement.querySelector('.ql-editor');
            if (editorContainer) {
              editorContainer.setAttribute('contenteditable', 'true');
            }
          }
        }
      }
    },
  },
  mounted() {
    this.init();
    // 确保按钮已添加（双重保障）
    this.$nextTick(() => {
      if (!this.$refs.editor || !this.$refs.editor.querySelector('.ql-source')) {
        this.addSourceButton();
      }
    });
  },
  beforeDestroy() {
    this.Quill = null;
  },
  methods: {
    init() {
      const editor = this.$refs.editor;
      this.Quill = new Quill(editor, this.options);
      
      // 注册自定义工具栏按钮
      let toolbar = this.Quill.getModule("toolbar");
      
      // 如果设置了上传地址则自定义图片上传事件
      if (this.type == 'url') {
        toolbar.addHandler("image", (value) => {
          if (value) {
            this.$refs.upload.$children[0].$refs.input.click();
          } else {
            this.Quill.format("image", false);
          }
        });
      }
      
      // 注册自定义源码按钮处理器
      toolbar.addHandler("source", () => {
        this.showSourceCode();
      });
      
      // 添加源代码按钮到工具栏 - 使用多重检查确保工具栏已渲染
      this.addSourceButton();
      
      this.Quill.pasteHTML(this.currentValue);
      this.Quill.on("text-change", (delta, oldDelta, source) => {
        const html = this.$refs.editor.children[0].innerHTML;
        const text = this.Quill.getText();
        const quill = this.Quill;
        this.currentValue = html;
        this.$emit("input", html);
        this.$emit("on-change", { html, text, quill });
      });
      this.Quill.on("text-change", (delta, oldDelta, source) => {
        this.$emit("on-text-change", delta, oldDelta, source);
      });
      this.Quill.on("selection-change", (range, oldRange, source) => {
        this.$emit("on-selection-change", range, oldRange, source);
      });
      this.Quill.on("editor-change", (eventName, ...args) => {
        this.$emit("on-editor-change", eventName, ...args);
      });
    },
    // 上传前校检格式和大小
    handleBeforeUpload(file) {
      const type = ["image/jpeg", "image/jpg", "image/png", "image/svg"];
      const isJPG = type.includes(file.type);
      // 检验文件格式
      if (!isJPG) {
        this.$message.error(`图片格式错误!`);
        return false;
      }
      // 校检文件大小
      if (this.fileSize) {
        const isLt = file.size / 1024 / 1024 < this.fileSize;
        if (!isLt) {
          this.$message.error(`上传文件大小不能超过 ${this.fileSize} MB!`);
          return false;
        }
      }
      return true;
    },
    handleUploadSuccess(res, file) {
      // 如果上传成功
      if (res.code == 200) {
        // 获取富文本组件实例
        let quill = this.Quill;
        // 获取光标所在位置
        let length = quill.getSelection().index;
        // 插入图片  res.url为服务器返回的图片地址
        quill.insertEmbed(length, "image", process.env.VUE_APP_BASE_API + res.fileName);
        // 调整光标到最后
        quill.setSelection(length + 1);
      } else {
        this.$message.error("图片插入失败");
      }
    },
    handleUploadError() {
      this.$message.error("图片插入失败");
    },
    // 移除遮罩层
    removeModalOverlay() {
      // 查找所有遮罩层元素
      const modals = document.querySelectorAll('.v-modal');
      modals.forEach((modal) => {
        // 检查是否是 z-index 为 2014 的遮罩层
        const zIndex = window.getComputedStyle(modal).zIndex;
        if (zIndex === '2014' || modal.style.zIndex === '2014') {
          modal.style.display = 'none';
          modal.style.visibility = 'hidden';
          modal.style.opacity = '0';
        }
      });
    },
    // 显示源代码对话框
    showSourceCode() {
      // 让编辑器失去焦点，防止键盘事件被编辑器捕获
      if (this.Quill) {
        // 临时禁用编辑器，防止键盘事件被捕获
        this.Quill.enable(false);
        this.Quill.blur();
        
        const editorElement = this.$refs.editor;
        if (editorElement) {
          // 移除编辑器的焦点状态
          const editorContainer = editorElement.querySelector('.ql-editor');
          if (editorContainer) {
            editorContainer.blur();
            // 设置不可编辑，防止意外编辑
            editorContainer.setAttribute('contenteditable', 'false');
          }
        }
      }
      
      // 获取当前编辑器的 HTML 内容
      let html = "";
      if (this.Quill && this.$refs.editor) {
        html = this.$refs.editor.children[0].innerHTML;
      } else {
        html = this.currentValue || "";
      }
      
      // 格式化 HTML（可选，让代码更易读）
      this.sourceCodeContent = this.formatHTML(html);
      this.sourceCodeDialogVisible = true;
      
      // 对话框打开后，将焦点移到文本域
      this.$nextTick(() => {
        // 移除遮罩层
        this.removeModalOverlay();
        
        // 将焦点设置到文本域
        if (this.$refs.sourceCodeTextarea && this.$refs.sourceCodeTextarea.$el) {
          const textarea = this.$refs.sourceCodeTextarea.$el.querySelector('textarea');
          if (textarea) {
            // 延迟一点时间确保对话框完全渲染
            setTimeout(() => {
              textarea.focus();
              // 将光标移到文本末尾
              textarea.setSelectionRange(textarea.value.length, textarea.value.length);
            }, 100);
          }
        }
      });
    },
    // 格式化 HTML 代码（简单的格式化）
    formatHTML(html) {
      if (!html) return "";
      
      // 简单的 HTML 格式化
      let formatted = html
        .replace(/></g, '>\n<')
        .replace(/^[\s\n]+|[\s\n]+$/g, '');
      
      // 增加缩进（可选）
      let indent = 0;
      return formatted.split('\n').map(line => {
        line = line.trim();
        if (line === '') return '';
        
        if (line.match(/^<\/\w+/)) {
          indent--;
        }
        
        const indented = '  '.repeat(Math.max(0, indent)) + line;
        
        if (line.match(/^<\w+[^>]*[^\/]>$/) && !line.match(/^<(img|br|hr|input|meta|link)/i)) {
          indent++;
        }
        
        return indented;
      }).join('\n');
    },
    // 清理源代码中的格式化换行符（保留 HTML 结构）
    cleanSourceCode(html) {
      if (!html) return "";
      
      // 移除源码编辑器中的普通换行符和格式化空白
      // 这些换行符在应用时会被 Quill 错误地转换为 <br> 或 <p><br></p>
      
      // 第一步：移除标签之间的所有换行符和空白（这些是格式化用的）
      let cleaned = html.replace(/>\s*[\r\n]+\s*</g, '><');
      
      // 第二步：移除标签之间的多余空格
      cleaned = cleaned.replace(/>\s+</g, '><');
      
      // 第三步：处理标签内部的换行
      // 对于标签内容（标签之间的文本），移除单独的换行符（这些会被转换为 <br>）
      // 但保留 HTML 标签结构
      cleaned = cleaned.replace(/(<[^>]+>)([^<]*)/g, (match, tag, content) => {
        // 如果标签后有内容，清理内容中的换行符
        if (content) {
          // 移除换行符，但保留一个空格（如果原内容中有空格的话）
          const cleanedContent = content.replace(/[\r\n]+/g, ' ').replace(/\s+/g, ' ');
          return tag + cleanedContent;
        }
        return match;
      });
      
      // 第四步：最终清理多余的连续空格
      cleaned = cleaned.replace(/\s+/g, ' ').trim();
      
      // 第五步：清理标签属性中的多余空格
      cleaned = cleaned.replace(/(\w+)\s*=\s*"([^"]*)"/g, '$1="$2"');
      cleaned = cleaned.replace(/(\w+)\s*=\s*'([^']*)'/g, "$1='$2'");
      
      return cleaned.trim();
    },
    // 应用源代码到编辑器
    applySourceCode() {
      if (!this.Quill) return;
      
      try {
        // 清理源代码：移除格式化换行符，只保留实际的 HTML 结构
        let cleanedHtml = this.cleanSourceCode(this.sourceCodeContent);
        
        // 如果清理后的 HTML 为空，则使用原始内容
        if (!cleanedHtml) {
          cleanedHtml = this.sourceCodeContent.trim();
        }
        
        // 先清空编辑器内容，然后设置新内容
        this.Quill.setText('');
        // 使用 pasteHTML 直接设置 HTML 内容
        this.Quill.pasteHTML(cleanedHtml);
        
        // 更新当前值
        const html = this.$refs.editor.children[0].innerHTML;
        this.currentValue = html;
        this.$emit("input", html);
        this.$emit("on-change", { 
          html, 
          text: this.Quill.getText(), 
          quill: this.Quill 
        });
        
        // 关闭对话框
        this.sourceCodeDialogVisible = false;
        this.$message.success("源代码已应用");
        
        // 恢复编辑器可编辑状态
        this.$nextTick(() => {
          if (this.Quill) {
            this.Quill.enable(true);
            const editorElement = this.$refs.editor;
            if (editorElement) {
              const editorContainer = editorElement.querySelector('.ql-editor');
              if (editorContainer) {
                editorContainer.setAttribute('contenteditable', 'true');
              }
            }
          }
        });
      } catch (error) {
        console.error("应用源代码失败:", error);
        this.$message.error("应用源代码失败，请检查 HTML 格式是否正确");
      }
    },
    // 取消源代码编辑
    cancelSourceCode() {
      this.sourceCodeDialogVisible = false;
      this.sourceCodeContent = "";
      
      // 恢复编辑器可编辑状态
      if (this.Quill) {
        this.$nextTick(() => {
          this.Quill.enable(true);
          const editorElement = this.$refs.editor;
          if (editorElement) {
            const editorContainer = editorElement.querySelector('.ql-editor');
            if (editorContainer) {
              editorContainer.setAttribute('contenteditable', 'true');
            }
          }
        });
      }
    },
    // 添加源码按钮到工具栏
    addSourceButton() {
      const tryAddButton = () => {
        // 尝试多种方式查找工具栏
        let toolbarContainer = null;
        
        // 方式1: 在 editor ref 中查找
        if (this.$refs.editor) {
          toolbarContainer = this.$refs.editor.querySelector('.ql-toolbar');
        }
        
        // 方式2: 在 editor-wrapper 中查找
        if (!toolbarContainer && this.$refs.editor && this.$refs.editor.parentElement) {
          toolbarContainer = this.$refs.editor.parentElement.querySelector('.ql-toolbar');
        }
        
        // 方式3: 通过 Quill 实例查找
        if (!toolbarContainer && this.Quill && this.Quill.container) {
          const container = this.Quill.container;
          if (container.parentElement) {
            toolbarContainer = container.parentElement.querySelector('.ql-toolbar');
          }
        }
        
        // 方式4: 全局查找最近的工具栏
        if (!toolbarContainer && this.$refs.editor) {
          let parent = this.$refs.editor.parentElement;
          while (parent && !toolbarContainer) {
            toolbarContainer = parent.querySelector('.ql-toolbar');
            parent = parent.parentElement;
          }
        }
        
        if (toolbarContainer) {
          // 检查是否已经添加过按钮，避免重复添加
          if (toolbarContainer.querySelector('.ql-source')) {
            return;
          }
          
          // 创建分隔符容器
          const separator = document.createElement('span');
          separator.className = 'ql-formats source-button-wrapper';
          separator.style.cssText = 'margin-left: 8px !important; border-left: 1px solid rgba(224, 224, 224, 0.6) !important; padding-left: 8px !important; display: inline-block !important;';
          
          // 创建源码按钮
          const sourceButton = document.createElement('button');
          sourceButton.className = 'ql-source';
          sourceButton.type = 'button';
          sourceButton.setAttribute('data-value', 'source');
          sourceButton.setAttribute('aria-label', '查看/编辑HTML源代码');
          sourceButton.title = '查看/编辑HTML源代码';
          sourceButton.innerHTML = `
            <svg viewBox="0 0 24 24" style="width: 18px; height: 18px;" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
              <path d="M16 18L22 12L16 6"></path>
              <path d="M8 6L2 12L8 18"></path>
            </svg>
          `;
          sourceButton.style.cssText = `
            width: 32px;
            height: 28px;
            padding: 0;
            margin: 0;
            border: none;
            border-radius: 4px;
            background-color: transparent;
            color: #606266;
            cursor: pointer;
            display: inline-flex;
            align-items: center;
            justify-content: center;
          `;
          
          sourceButton.addEventListener('click', (e) => {
            e.preventDefault();
            e.stopPropagation();
            this.showSourceCode();
          });
          
          separator.appendChild(sourceButton);
          toolbarContainer.appendChild(separator);
          
          console.log('源码按钮已成功添加到工具栏');
          return true;
        }
        
        return false;
      };
      
      // 立即尝试
      if (tryAddButton()) {
        return;
      }
      
      // 使用 nextTick 延迟尝试
      this.$nextTick(() => {
        if (tryAddButton()) {
          return;
        }
        
        // 如果还不行，使用 setTimeout 再次尝试
        setTimeout(() => {
          if (tryAddButton()) {
            return;
          }
          
          // 最后一次尝试，延迟更长时间
          setTimeout(() => {
            tryAddButton();
          }, 300);
        }, 100);
      });
    },
  },
};
</script>

<style>
.editor, .ql-toolbar {
  white-space: pre-wrap !important;
  line-height: normal !important;
}
.quill-img {
  display: none;
}
.ql-snow .ql-tooltip[data-mode="link"]::before {
  content: "请输入链接地址:";
}
.ql-snow .ql-tooltip.ql-editing a.ql-action::after {
  border-right: 0px;
  content: "保存";
  padding-right: 0px;
}
.ql-snow .ql-tooltip[data-mode="video"]::before {
  content: "请输入视频地址:";
}
/* 源代码按钮样式 - 优雅极简风格 */
.ql-snow .ql-toolbar .source-button-wrapper {
  margin-left: 8px !important;
  border-left: 1px solid rgba(224, 224, 224, 0.6) !important;
  padding-left: 8px !important;
  display: inline-block !important;
}

.ql-snow .ql-toolbar button.ql-source {
  width: 32px;
  height: 28px;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 4px;
  background-color: transparent;
  color: #606266;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.ql-snow .ql-toolbar button.ql-source::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, #409EFF 0%, #66b1ff 100%);
  transform: translate(-50%, -50%);
  transition: width 0.3s ease, height 0.3s ease;
  opacity: 0.1;
  z-index: 0;
}

.ql-snow .ql-toolbar button.ql-source:hover {
  color: #409EFF;
  background-color: rgba(64, 158, 255, 0.08);
  transform: translateY(-1px);
}

.ql-snow .ql-toolbar button.ql-source:hover::before {
  width: 100%;
  height: 100%;
}

.ql-snow .ql-toolbar button.ql-source:active {
  transform: translateY(0);
  background-color: rgba(64, 158, 255, 0.15);
}

.ql-snow .ql-toolbar button.ql-source svg {
  position: relative;
  z-index: 1;
  transition: transform 0.2s ease;
}

.ql-snow .ql-toolbar button.ql-source:hover svg {
  transform: scale(1.1);
}
/* 编辑器容器样式 */
.editor-wrapper {
  position: relative;
}
/* 源代码对话框样式 - 优雅极简风格 */
::v-deep .source-code-dialog {
  border-radius: 8px;
  overflow: hidden;
}

/* 禁用或隐藏遮罩层 - 多重保障确保遮罩层被隐藏 */
body > .v-modal[style*="z-index: 2014"] {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
}

/* 确保对话框层级足够高 */
::v-deep .source-code-dialog .el-dialog {
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
  z-index: 2015 !important; /* 确保在遮罩层之上 */
  position: relative;
}

::v-deep .source-code-dialog .el-dialog__header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid rgba(224, 224, 224, 0.5);
  background: linear-gradient(to bottom, #ffffff 0%, #fafafa 100%);
}

::v-deep .source-code-dialog .el-dialog__title {
  font-size: 16px;
  font-weight: 500;
  color: #303133;
  letter-spacing: 0.5px;
}

::v-deep .source-code-dialog .el-dialog__body {
  padding: 24px;
  background: #fafbfc;
}

::v-deep .source-code-dialog .el-dialog__footer {
  padding: 16px 24px 20px;
  border-top: 1px solid rgba(224, 224, 224, 0.5);
  background: #ffffff;
}

.source-code-container {
  margin: 0;
}

.source-code-header {
  margin-bottom: 12px;
  padding: 8px 12px;
  background: linear-gradient(135deg, rgba(64, 158, 255, 0.06) 0%, rgba(102, 177, 255, 0.04) 100%);
  border-radius: 6px;
  border-left: 3px solid #409EFF;
}

.source-code-tip {
  font-size: 13px;
  color: #606266;
  line-height: 1.6;
  display: flex;
  align-items: center;
}

.source-code-tip::before {
  content: '💡';
  margin-right: 8px;
  font-size: 14px;
}

.source-code-textarea {
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 13px;
}

.source-code-textarea ::v-deep .el-textarea__inner {
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  line-height: 1.75;
  letter-spacing: 0.3px;
  color: #2c3e50;
  background: linear-gradient(to bottom, #ffffff 0%, #fafbfc 100%);
  border: 1px solid rgba(224, 224, 224, 0.8);
  border-radius: 6px;
  resize: vertical;
  padding: 16px;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.03);
}

.source-code-textarea ::v-deep .el-textarea__inner:hover {
  border-color: #c0c4cc;
  box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.05);
}

.source-code-textarea ::v-deep .el-textarea__inner:focus {
  border-color: #409EFF;
  background-color: #ffffff;
  box-shadow: 0 0 0 3px rgba(64, 158, 255, 0.1), inset 0 1px 3px rgba(0, 0, 0, 0.03);
  outline: none;
}

::v-deep .source-code-dialog .dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

::v-deep .source-code-dialog .cancel-btn {
  padding: 10px 20px;
  border-radius: 6px;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid #dcdfe6;
  background: #ffffff;
  color: #606266;
}

::v-deep .source-code-dialog .cancel-btn:hover {
  color: #409EFF;
  border-color: #c6e2ff;
  background-color: rgba(64, 158, 255, 0.05);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(64, 158, 255, 0.15);
}

::v-deep .source-code-dialog .apply-btn {
  padding: 10px 24px;
  border-radius: 6px;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  background: linear-gradient(135deg, #409EFF 0%, #66b1ff 100%);
  border: none;
  box-shadow: 0 2px 8px rgba(64, 158, 255, 0.3);
}

::v-deep .source-code-dialog .apply-btn:hover {
  background: linear-gradient(135deg, #66b1ff 0%, #409EFF 100%);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(64, 158, 255, 0.4);
}

::v-deep .source-code-dialog .apply-btn:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(64, 158, 255, 0.3);
}
.ql-snow .ql-picker.ql-size .ql-picker-label::before,
.ql-snow .ql-picker.ql-size .ql-picker-item::before {
  content: "14px";
}
.ql-snow .ql-picker.ql-size .ql-picker-label[data-value="small"]::before,
.ql-snow .ql-picker.ql-size .ql-picker-item[data-value="small"]::before {
  content: "10px";
}
.ql-snow .ql-picker.ql-size .ql-picker-label[data-value="large"]::before,
.ql-snow .ql-picker.ql-size .ql-picker-item[data-value="large"]::before {
  content: "18px";
}
.ql-snow .ql-picker.ql-size .ql-picker-label[data-value="huge"]::before,
.ql-snow .ql-picker.ql-size .ql-picker-item[data-value="huge"]::before {
  content: "32px";
}
.ql-snow .ql-picker.ql-header .ql-picker-label::before,
.ql-snow .ql-picker.ql-header .ql-picker-item::before {
  content: "文本";
}
.ql-snow .ql-picker.ql-header .ql-picker-label[data-value="1"]::before,
.ql-snow .ql-picker.ql-header .ql-picker-item[data-value="1"]::before {
  content: "标题1";
}
.ql-snow .ql-picker.ql-header .ql-picker-label[data-value="2"]::before,
.ql-snow .ql-picker.ql-header .ql-picker-item[data-value="2"]::before {
  content: "标题2";
}
.ql-snow .ql-picker.ql-header .ql-picker-label[data-value="3"]::before,
.ql-snow .ql-picker.ql-header .ql-picker-item[data-value="3"]::before {
  content: "标题3";
}
.ql-snow .ql-picker.ql-header .ql-picker-label[data-value="4"]::before,
.ql-snow .ql-picker.ql-header .ql-picker-item[data-value="4"]::before {
  content: "标题4";
}
.ql-snow .ql-picker.ql-header .ql-picker-label[data-value="5"]::before,
.ql-snow .ql-picker.ql-header .ql-picker-item[data-value="5"]::before {
  content: "标题5";
}
.ql-snow .ql-picker.ql-header .ql-picker-label[data-value="6"]::before,
.ql-snow .ql-picker.ql-header .ql-picker-item[data-value="6"]::before {
  content: "标题6";
}
.ql-snow .ql-picker.ql-font .ql-picker-label::before,
.ql-snow .ql-picker.ql-font .ql-picker-item::before {
  content: "标准字体";
}
.ql-snow .ql-picker.ql-font .ql-picker-label[data-value="serif"]::before,
.ql-snow .ql-picker.ql-font .ql-picker-item[data-value="serif"]::before {
  content: "衬线字体";
}
.ql-snow .ql-picker.ql-font .ql-picker-label[data-value="monospace"]::before,
.ql-snow .ql-picker.ql-font .ql-picker-item[data-value="monospace"]::before {
  content: "等宽字体";
}
</style>
